package com.iamteer.dao;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.iamteer.entity.Admin;
import com.iamteer.utils.JdbcUtils;

public class AdminDao {
	public Admin login(Admin admin) {
		String sql = "select * from admin where userName=? and pwd=?";
		try {
			return JdbcUtils.getQueryRunner().query(sql, 
					new BeanHandler<Admin>(Admin.class), 
					admin.getUserName(),
					admin.getPwd());
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public List<Admin> getAll() {
		String sql = "select * from admin";
		try {
			return JdbcUtils.getQueryRunner().query(sql, new BeanListHandler<Admin>(Admin.class));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
